package com.snowRemovingUser.controller;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.snowRemovingUser.domain.TPrediction;
import com.snowRemovingUser.service.ITPredictionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 预测报表Controller
 *
 * @author lg
 * @date 2024-04-08
 */
@RestController
@RequestMapping("/snowRemoving/prediction")
public class TPredictionController extends BaseController
{
    @Autowired
    private ITPredictionService tPredictionService;

    /**
     * 查询预测报表列表
     */
    @PreAuthorize("@ss.hasPermi('snowRemoving:prediction:list')")
    @GetMapping("/list")
    public TableDataInfo list(TPrediction tPrediction)
    {
        startPage();
        List<TPrediction> list = tPredictionService.selectTPredictionList(tPrediction);
        return getDataTable(list);
    }

    /**
     * 导出预测报表列表
     */
    @PreAuthorize("@ss.hasPermi('snowRemoving:prediction:export')")
    @Log(title = "预测报表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TPrediction tPrediction)
    {
        List<TPrediction> list = tPredictionService.selectTPredictionList(tPrediction);
        ExcelUtil<TPrediction> util = new ExcelUtil<TPrediction>(TPrediction.class);
        util.exportExcel(response, list, "预测报表数据");
    }

    /**
     * 获取预测报表详细信息
     */
    @PreAuthorize("@ss.hasPermi('snowRemoving:prediction:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tPredictionService.selectTPredictionById(id));
    }

    /**
     * 新增预测报表
     */
    @PreAuthorize("@ss.hasPermi('snowRemoving:prediction:add')")
    @Log(title = "预测报表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TPrediction tPrediction)
    {
        return toAjax(tPredictionService.insertTPrediction(tPrediction));
    }

    /**
     * 修改预测报表
     */
    @PreAuthorize("@ss.hasPermi('snowRemoving:prediction:edit')")
    @Log(title = "预测报表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TPrediction tPrediction)
    {
        return toAjax(tPredictionService.updateTPrediction(tPrediction));
    }

    /**
     * 删除预测报表
     */
    @PreAuthorize("@ss.hasPermi('snowRemoving:prediction:remove')")
    @Log(title = "预测报表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tPredictionService.deleteTPredictionByIds(ids));
    }




    @GetMapping("/latest")
    @Anonymous
    public AjaxResult latestInfo(String road){

        return success(tPredictionService.latestInfo(road));
    }






    @GetMapping("/releaseInfo")
    public AjaxResult predictionRelease(String queryTime){



        return success(tPredictionService.release(queryTime));

    }















}
